package export.monster
{
	import base.BaseBitmapDataClip;
	import base.BaseBitmapDataPool;
	import base.BaseHero;
	import base.BaseMonster;
	import base.BaseObject;
	
	import com.dusk.util.ResUtil;
	
	import flash.display.Sprite;
	
	import flash.geom.Point;
	
	
	public class VoodooDoll extends BaseMonster
	{
		
		public function VoodooDoll(param1:BaseObject, param2:BaseObject)
		{
			var _loc3_:int = 0;
			super();
			this.sourceRole = param2;
			this.followObject = param1;
			this.horizonSpeed = 3;
			if (param2 is BaseHero)
			{
				_loc3_ = int((param2 as BaseHero).getPlayer().returnSkillLevelBySkillName("wdww"));
				this.setHp(Number((param1 as BaseMonster).getHpMax()) * Math.sqrt(_loc3_) * 0.0766);
				this.setSHp(Number((param1 as BaseMonster).getHpMax()) * Math.sqrt(_loc3_) * 0.0766);
				this.mavo.def = BaseMonster(param1).getDef();
				this.mavo.magicDef = BaseMonster(param1).getMagicDef();
			}
			else
			{
				this.setHp(9999999);
				this.setSHp(9999999);
				this.mavo.def = 0;
				this.mavo.magicDef = 0;
			}
			this.mavo.attackRange = 250;
			this.mavo.alertRange = 1000;
			this.mavo.exp = 0;
			this.mavo.gxp = 0;
			this.mavo.isBoss = false;
			this.timeCount = gc.frameClips * 10;
			this.setAction("walk");
		}
		
		private var followObject:BaseObject;
		private var sourceRole:BaseObject;
		private var timeCount:uint;
		
		override protected function initBBDC():void
		{
			var _loc1_:* = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("Role4Hit5");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 116, 2 * 60, new Point(0, 0));
				bbdc.setOffsetXY(0, 0);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 6], [2, 2, 2, 9], [2, 2, 2, 2, 32]]);
				bbdc.setFrameCount([6, 4, 1, 5, 4, 5]);
				bbdc.setEnterFrameCallBack(enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("wuduwawa--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(param1:String):void
		{
			param1 = "walk";
			super.setAction(param1);
			var _loc2_:Point = this.bbdc.getCurPoint();
			switch (param1)
			{
				case "walk":
					if (_loc2_.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(param1);
			}
		}
		
		override protected function scriptFrameOverFunc(param1:int):void
		{
			var _loc2_:String = this.bbdc.getState();
			switch (_loc2_)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
			}
		}
		
		override protected function exitFrameFunc(param1:Point):void
		{
		}
		
		override public function reduceHp(param1:int, param2:Boolean = false):void
		{
			super.reduceHp(param1, param2);
			if (Boolean(this.sourceRole) && Boolean(this.followObject))
			{
				if (this.followObject)
				{
					if (this.followObject is BaseMonster)
					{
						this.followObject.reduceHp(param1, false);
					}
					else if (this.followObject is BaseHero)
					{
						this.followObject.reduceHp(param1, false);
					}
				}
			}
			if (this.isDead())
			{
				this.destroy();
			}
		}
		
		override public function setAttackBack(param1:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			if (this.timeCount > 0)
			{
				--this.timeCount;
			}
			if (this.followObject)
			{
				if (AUtils.GetDisBetweenTwoObj(this, this.followObject) > 100)
				{
					if (Number(this.timeCount) % gc.frameClips == 0)
					{
						if (this.x > this.followObject.x)
						{
							this.turnLeft();
						}
						else
						{
							this.turnRight();
						}
					}
				}
				else
				{
					this.setStatic();
				}
				if (Boolean(this.followObject.isDead()) || this.timeCount == 0)
				{
					this.destroy();
				}
			}
		}
		
		override public function destroy():void
		{
			super.destroy();
			this.followObject = null;
			this.sourceRole = null;
		}
		
		public function getSourceRole():BaseObject
		{
			return this.sourceRole;
		}
	}
}
